import request from "../request/request";

type TUserParams = {
  loginname: string;
  password: string;
};

interface IUserRegister {
  tel: string;
  password: string;
}

interface IuserChangePass {
  userid?: string;
  oldpassword: string;
  newpassword: string;
}

interface Iaddcar {
  userid: string;
  porid: any
  num: string;
}

// 添加地址
interface IAddAddress {
  userid: string;
  name: string;
  tel: string;
  province: string;
  city: string;
  county: string;
  addressDetail: string;
  isDefault: boolean;
}

//更新地址
interface IAddressUpdate {
  addressid: string;
  userid: string;
  name: string;
  tel: string;
  province: string;
  city: string;
  county: string;
  addressDetail: string;
  isDefault: boolean;
}


export const userLogin = (params: TUserParams) => {
  return request.post("/user/login", params);
};

export const msgCode = (params: { tel: string }) => {
  return request.post("/user/dosendmsgcode", params);
};

export const userRegister = (params: IUserRegister) => {
  return request.post("/user/dofinishregister", params);
};

export const getSeckillList = (params: {
  count: number;
  limitNum?: number;
}) => {
  return request.get(
    `/pro/seckilllist?count=${params.count}&limitNum=${params.limitNum}`
  );
};

export const getProList = (params: { count: number; limitNum?: number }) => {
  return request.get(
    `/pro/list?count=${params.count}&limitNum=${params.limitNum}`
  );
};

export const getProduceDetail = (parms: string) => {
  return request.get(`/pro/detail/${parms}`);
};

//  修改密码
export const userChangePass = (params: IuserChangePass) => {
  return request.post("/api/changemyinfo", params);
};

// 获取商品详情信息
export const proDetail = (params: { proid: string }) => {
  return request.get(`/pro/detail/${params.proid}`);
};


//  加入购物车
export const addCar = (params: any) => {
  return request.post("/cart/add", params);
};
//  查看购物车
export const lookCarts = (params: { userid: string }) => {
  return request.post("/cart/list", params);
};
// 删除购物车单条数据
export const delCarts = (params: { cartid: string }) => {
  return request.post("/cart/remove", params);
};
// 删除当前用户的购物车数据
export const delAllCarts = (params: { userid: string }) => {
  return request.post("/cart/removeall", params);
};
// 更新购物车数量
export const updatenum = (params: { cartid: string; num: number }) => {
  return request.post("/cart/updatenum", params);
};





// 分页接口
export const categoryBank = (params: { category: string }) => {
  return request.get("/pro/categorybrandlist", { params });
};

export const getCategoryBrandproList = (params: {
  category: string;
  brand: string;
}) => {
  return request.get("/pro/categorybrandprolist", {
    params,
  });
};
export const categoryList = () => {
  return request.get("/pro/categorylist");
};



// 地址接口
// 添加地址
export const addAddress = (params: IAddAddress) => {
  return request.post("address/add", params);
};
// 删除地址
export const delAddress = (params: { addressid: string }) => {
  return request.post("address/delete", params);
};
// 地址列表
export const addressList = (params: { userid: string }) => {
  return request.get("address/list",{params});
};
// 更新地址
export const addressUpdate = (params:IAddressUpdate)=>{
  return request.post("address/update", params);
}
// 查询默认地址
export const defaultAddress = (params: { userid: string }) => {
  return request.post("address/defaultAddress", params);
};